import { View, Input } from '@tarojs/components';
import Taro, { useState, Config, useEffect } from '@tarojs/taro';
import './index.module.less';
import { debounce, throttle, downImg, localityImg, dateFormat, taost, countDown, sub, getAddress } from "~/common/common"
import logo from "./images/logo.png"
import MMButton from '~/modules/@wmeimob/taro-design/src/components/button';
import DownTime from "~/components/countDown"
import PassWordBox from "~/components/passWordBox"
import Alert from "~/components/alert"
const Demo = () => {
    const [time, useDate] = useState({} as any)
    const [phone, usePhone] = useState(null as any)
    useEffect(() => {

    }, [])

    function getTime() {
        setInterval(() => {
            useDate(sub(1606510111621))
        }, 1000)
    }
    // 下载单张图片
    function jumpImgOne() {
        // 本地图
        downImg(logo, 1)
        // 网络图
        // downImg('https://ruice.oss-cn-shanghai.aliyuncs.com/ruice/XrX5RAZ8S4K63h5GmHP4fK2XhGajBesH.jpg', 2)
    }
    // 获取地址
    async function jumpAddress() {
        const data = await getAddress()
        console.log(data)
    }
    // 多张网络图同时下载，顺序不变 绘制海报有多张网络图需要
    async function jumpImgAll() {
        console.log('图片过大，稍作等待')
        const imgList = [
            'https://yingnuo.oss-cn-beijing.aliyuncs.com/yingnuo/Nb2Ndbkpsz3fjkHGjHSzftarZQX8PfkX.jpg',
            'https://jinlin-property.oss-cn-shanghai.aliyuncs.com/img/J2P3bnBEEzfRrzpAtXNBBMAXNf2mwbykw7bt',
            'https://yingnuo.oss-cn-beijing.aliyuncs.com/yingnuo/3AJkxfZJeNcP7NNKrB4YTN5A2QdAKtCN.jpg'
        ]
        const data = await localityImg(imgList)
        data.map((item: any) => {
            console.log(item, 'item')
        })
    }

    function fnHandleScroll(event) {
        console.log('scroll触发了：', event)
    }

    // 弹框
    function jumpToast() {
        taost.success("bbbb")
    }
    function getValue(event) {
        usePhone(event.detail.value)
    }
    function ok() {
        console.log(11)
    }
    function cancle() {
        console.log(2222)
    }
    // Date.now()  +new Date() new Date().valueOf()  new Date().getTime()    Date.parse(new Date())//当前时间戳
    return (
        <View className="page" >
            <Alert cancleColor="#33" okColor="red" title="一根小草" suceess={ok} cancle={cancle}>
                <View>2222</View>
            </Alert>
            {/* <PassWordBox num={6} titleText="输入支付密码" callBack={ok} cancelFun={cancle} /> */}
            <Input className='ebounceInput' placeholder="请输入手机号" onInput={getValue} />
            <DownTime phone={phone} />
            <View>时间戳转换：{dateFormat(Number(new Date()))}</View>
            <MMButton onClick={jumpAddress}>获取地址</MMButton>
            <View className='spacing' />
            <MMButton onClick={jumpImgOne}>保存图片</MMButton>
            <View className='spacing' />
            <MMButton onClick={jumpImgAll}>下载网络图片（绘制海报需要）</MMButton>
            <View className='spacing' />
            <MMButton onClick={jumpToast}>弹框</MMButton>
            <View className='spacing' />
            <MMButton onClick={throttle(() =>
                fnHandleScroll(2)
            )}>防止重复提交</MMButton>
            <Input className='ebounceInput' placeholder="hook下的防抖方法" onInput={debounce((event) => {
                fnHandleScroll(event)
            })} />

            {/* <MMButton >{`${time.days}:${time.hours}:${time.minutes}:${time.seconds}`}</MMButton> */}
        </View >
    );
}
Demo.config = {
    navigationBarTitleText: '测试'
};
export default Demo